package servlet;


import dao.MetaverseProductMapper;
import org.apache.ibatis.session.SqlSession;
import utils.MyBatisUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/metaverseProductUpdateServlet")
public class metaverseProductUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        SqlSession sqlSession=null;
       try {
           sqlSession= MyBatisUtil.createSqlSession();
           int id =Integer.parseInt(request.getParameter("id"));
           int flag = Integer.parseInt(request.getParameter("flag"))==1?0:1;
           int count=sqlSession.getMapper(MetaverseProductMapper.class).updata(id,flag);
           sqlSession.commit();
           if(count>0){
               out.print("true");
           }else{
               out.print("false");
           }
       }catch (Exception e){
           e.printStackTrace();
       }finally {
           MyBatisUtil.closeSqlSession(sqlSession);
       }
        out.flush();
        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
